package com.myshop.entity;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class R<T> {

    private Integer code;
    private String msg;
    private T data;

    /**
     * 返回一个成功的R对象
     * @return
     */
    public static <S> R succ(S data){
        return new R()
                .setCode(200)
                .setMsg("成功")
                .setData(data);
    }

    /**
     * 返回一个失败的R对象
     * @return
     */
    public static R fail(Integer code, String msg){
        return new R()
                .setCode(code)
                .setMsg(msg);
    }
}
